package com.hongxun.budget.ui.fragment.sg;

import android.widget.EditText;

import com.hongxun.budget.R;
import com.hongxun.budget.ui.fragment.BaseFragment;
import com.hongxun.budget.utils.SgDBUtils;
import com.hongxun.budget.utils.SPUtils;
import com.hongxun.budget.utils.SgStrKey;
import com.hongxun.greenentity.sg.CGroundEntity;

import java.util.Date;

import butterknife.BindView;

/**
 * 隐蔽工程信息详情：接地体
 */
public class EditGroundInfo extends BaseFragment {
    @BindView(R.id.et21)
    EditText et21;
    @BindView(R.id.et22)
    EditText et22;
    @BindView(R.id.et23)
    EditText et23;
    @BindView(R.id.et24)
    EditText et24;
    @BindView(R.id.et25)
    EditText et25;
    @BindView(R.id.et26)
    EditText et26;
    @BindView(R.id.et27)
    EditText et27;
    @BindView(R.id.et28)
    EditText et28;
    @BindView(R.id.et29)
    EditText et29;

    private CGroundEntity groundEntity;


    public EditGroundInfo() {
    }

    @Override
    public  int getLayoutId() {
        return R.layout.sg_fragment_editgroundinfo;
    }

    @Override
    public  void initView() {
        if (getArguments().getBoolean("isNewAdd", false)) {
            groundEntity = new CGroundEntity();
            groundEntity.setGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidxx, "")));
            groundEntity.setPGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidxm, "")));
            groundEntity.setMCGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidjl, "")));
            groundEntity.setGDatastate("新增");
            groundEntity.setGResult("合格");
            //默认值
            et29.setText(groundEntity.getGResult());
        } else {
            groundEntity = SgDBUtils.getCGround(String.valueOf(SPUtils.get(context, SgStrKey.uuidxx, "")));
            et21.setText(groundEntity.getGFormat());
            et22.setText(groundEntity.getGSoil());
            et23.setText(groundEntity.getGMass());
            et24.setText(groundEntity.getGDam());
            et25.setText(groundEntity.getGLength());
            et26.setText(groundEntity.getGWidth());
            et27.setText(groundEntity.getGDepth());
            et28.setText(groundEntity.getGResistance());
            et29.setText(groundEntity.getGResult());
        }
    }

    //保存
    public void saveData(String name) {
        String trim21 = et21.getText().toString().trim();
        String trim22 = et22.getText().toString().trim();
        String trim23 = et23.getText().toString().trim();
        String trim24 = et24.getText().toString().trim();
        String trim25 = et25.getText().toString().trim();//槽沟长度
        String trim26 = et26.getText().toString().trim();//槽沟宽度
        String trim27 = et27.getText().toString().trim();//槽沟深度
        String trim28 = et28.getText().toString().trim();//接地电阻值
        String trim29 = et29.getText().toString().trim();//检查结果
        groundEntity.setMCName(name);
        groundEntity.setGFormat(trim21);
        groundEntity.setGSoil(trim22);
        groundEntity.setGMass(trim23);
        groundEntity.setGDam(trim24);
        groundEntity.setGLength(trim25);
        groundEntity.setGWidth(trim26);
        groundEntity.setGDepth(trim27);
        groundEntity.setGResistance(trim28);
        groundEntity.setGResult(trim29);
        groundEntity.setGAddtime(new Date(System.currentTimeMillis()));
        SgDBUtils.upDataCGroundEntity(groundEntity);
    }

}
